home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.6 KB | 75 lines | [TEXT/ttxt] |
- -- <<<-
- module ThreadTest2 uses ScriptX end
- in module ThreadTest2
-
- -- threads demonstration
- -- use this version here, a slight revision of the one in the book,
- --
- -- cool stuff to try
- -- use the Listener window to play with the threads
- -- start them, stop them, restart them, kill them
- -- change their relative priorities and other properties
- -- change the size of thePipe and its other properties
- -- create more threads and activate them too
- -- see how many normal threads it takes to thrash the system
- -- see how many high-priority threads it takes to thrash the system
-
- object myWindow (Window)
- boundary:(new Rect x2:300 y2:50), fill:whiteBrush
- settings x:20, y:40
- end
- show myWindow
- -- create text string global
- object myTextBox (TextEdit)
- boundary:(myWindow.boundary), target:("musician" as Text)
- fill:whiteBrush, stroke:blackBrush
- end
- setDefaultAttr myTextBox @alignment @center
- append myWindow myTextBox
- show myWindow
-
- -- now set up the threads
- function classical thePipe -> (
- local composerList := #("Beethoven","Bach","Mozart","Haydn",
- "Stravinsky","Mahler","Debussy","Ravel","Sibelius","Lutoslawski")
- repeat while true do (
- write thePipe (getAny composerList)
- threadYield()
- )
- )
-
- function heavyMetal thePipe -> (
- local heavyMetalList := #("Aerosmith","Bon Jovi","Motley Crue",
- "Megadeath","Twisted Sister","Judas Priest","AC/DC","Metallica")
- repeat while true do (
- write thePipe (getAny heavyMetalList)
- threadYield()
- )
- )
-
- function listenTo thePipe -> -- this is the reading thread
- repeat while true do \
- myTextBox.target := (read thePipe) as Text
- object myPipe (PipeClass) maxSize:3 end
-
- -- create the three threads. They will start active.
- global classic := new Thread func:classical arg:myPipe priority:@user
- global metal := new Thread func:heavyMetal arg:myPipe priority:@user
- global listen := new Thread func:listenTo arg:myPipe priority:@user
-
-
-
- -- Here's another one to add to the system
- function playJazz thePipe -> (
- local composerList := #("Armstrong","Ellington","Parker","Hawkins",
- "Young","Monk","Mingus","Coltrane","Davis","Carla Bley")
- repeat while true do (
- write thePipe (getAny composerList)
- threadYield()
- )
- )
- global jazz:= new Thread func:playjazz arg:myPipe priority:@user
-
-
- -->>>
-